#!/bin/sh
# PCP QA Test No. 1529
# pmcd -L maxpmids testing
#
# Copyright (c) 2024 Ken McDonell.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check


_cleanup()
{
    cd $here
    [ -n "$pmcd_pid" ] && kill -TERM $pmcd_pid
    $sudo rm -rf $tmp $tmp.*
}

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e "s@$tmp@TMP@g" \
	-e '/No value(s) available/d' \
	-e '/Explicit instance identifier(s) required/d' \
	-e '/Unknown or illegal metric identifier/d' \
	-e '/Not Supported/d' \
	-e '/Try again. Information not currently available/d' \
    | $PCP_AWK_PROG '
/Result size exceeded/	{ exceed++; next }
			{ print }
END			{ if (exceed > 200) {
			    print "... more than 200 \"Result size exceeded\" errors"
			  }
			  else if (exceed == 0) {
			    ;
			  }
			  else {
			    print "...",exceed,"??? \"Result size exceeded\" errors"
			  }
			}'
}

# real QA test starts here
pmcd_args='-M 10'
_private_pmcd || _exit 1

for b in 10 11
do
    echo
    echo "fetch batch size $b"
    pminfo -v -b $b -h localhost sampledso 2>&1 \
    | _filter
done

echo
echo "interesting diagnostic lines ..."
cat $tmp/pmcd.log >>$seq_full
[ -s $tmp/pmcd.out ] && cat $tmp/pmcd.out
[ -s $tmp/pmcd.err ] && cat $tmp/pmcd.err

# success, all done
exit
